home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / fido / mmail.000 / mmail / mmail.0.1 / interface / main.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1996-01-27  |  8.4 KB  |  350 lines

  1. /*
  2.  * MultiMAIL offline mail reader
  3.  * 
  4.  
  5.    Written by Kolossvary Tamas (thomas@vma.bme.hu)
  6.  
  7.    This program is free software; you can redistribute it and/or modify
  8.    it under the terms of the GNU General Public License as published by
  9.    the Free Software Foundation; either version 2, or (at your option)
  10.    any later version.
  11.  
  12.    This program is distributed in the hope that it will be useful,
  13.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.    GNU General Public License for more details.
  16.  
  17.    You should have received a copy of the GNU General Public License
  18.    along with this program; if not, write to the Free Software
  19.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. #include <signal.h>
  22. #include <ctype.h>
  23. #include "interface.h"
  24.  
  25. mmail             mm;
  26. packet_list         *packetList;
  27. letter_list         *letterList;
  28. Welcome             welcome;
  29. PacketListWindow     packets;
  30. AreaListWindow       areas;
  31. LetterListWindow     letters;
  32. LetterWindow         letterwindow;
  33. HelpWindow          helpwindow;
  34. Interface         *interface;
  35. LittleAreaListWindow     *littleareas;
  36. AddressBook        addresses;
  37. int getstring(WINDOW *, int, int, char *, int, int, int);
  38.  
  39. WINDOW *screen;
  40.  
  41. void screen_init(int mode)    //mode = 1 ->background, mode = 0 ->no bkgd
  42. {
  43.  int     i, j; 
  44.  typedef int line[24];
  45.  typedef line pattern[5];
  46.  pattern text = {{1, 2, 7, 8, 11, 12, 17, 18, 33, 34, 35, 36, 43, 44, 0},
  47.          {1, 2, 3, 6, 7, 8, 11, 12, 13, 16, 17, 18, 32, 33, 36, 37,
  48.           42, 43, 44, 0},
  49.          {1, 2, 4, 5, 7, 8, 11, 12, 14, 15, 17, 18, 22, 23, 27, 28,
  50.           32, 33, 36, 37, 41, 43, 44, 0},
  51.          {1, 2, 7, 8, 11, 12, 17, 18, 23, 24, 26, 27, 32, 33, 36, 37, 
  52.           43, 44, 0},
  53.          {1, 2, 7, 8, 11, 12, 17, 18, 24, 25, 26, 29, 30, 33, 34, 35,
  54.           36, 39, 40, 43, 44, 46, 47, 0}};
  55.  
  56. /*
  57. 88    88  88    88              8888      88
  58. 888  888  888  888             88  88    888
  59. 88 88 88  88 88 88   88   88   88  88   8 88 
  60. 88    88  88    88    88 88    88  88     88
  61. 88    88  88    88     888  88  8888  88  88 88
  62. */
  63.  
  64.  printf("\033(K"); //this is for the special characters
  65.  initscr();
  66.  start_color();
  67.  init_pair(50, COLOR_WHITE, COLOR_BLACK);
  68.  init_pair(51, COLOR_MAGENTA, COLOR_BLACK);
  69.  init_pair(52, COLOR_BLUE, COLOR_BLACK);
  70.  cbreak();
  71.  noecho();
  72.  screen=newwin(0, 0, 0, 0);
  73.  leaveok(screen, TRUE);
  74.  keypad(screen, TRUE);
  75.  wattrset(screen, COLOR_PAIR(50));
  76.  if(mode)
  77.      for(i=0; i<COLS*(LINES-5); i++)
  78.             waddch(screen, ACS_BOARD);
  79.  wattrset(screen, COLOR_PAIR(52) | A_BOLD);
  80.  for(i=0; i < 5; i++)
  81.  {
  82.     j = 0; 
  83.     while(text[i][j] != 0)
  84.      {
  85.          mvwaddch(screen, i + 14, text[i][j] + 28, 
  86.              ACS_BOARD);
  87.         j++;
  88.      }
  89.  }
  90.  
  91.  wborder(screen, 0, 0, 0, 0, 0, 0, 0, 0);
  92.  mvwaddch(screen, 0, 2, ACS_RTEE);
  93.  wattrset(screen, COLOR_PAIR(50) | A_BOLD);
  94.  waddstr(screen, "MultiMAIL Bluewave reader V0.1"); 
  95.  wattrset(screen, COLOR_PAIR(52) | A_BOLD);
  96.  waddch(screen, ACS_LTEE);
  97.  wattrset(screen, COLOR_PAIR(51));
  98.  wmove(screen, LINES-5, 1);
  99.  whline(screen, ACS_HLINE, COLS-2);
  100.  
  101.  wnoutrefresh(screen);
  102. }
  103.  
  104. void mvwaddchar(WINDOW *window, int y, int x, char c)
  105. {
  106.  char tmp[2];
  107.  
  108.  tmp[0]=c;
  109.  tmp[1]='\0';
  110.  mvwaddstr(window, y, x, tmp);
  111. }
  112.  
  113. void handler(int mittomtenmi)
  114. {
  115.  nodelay(stdscr, TRUE); 
  116. }
  117.  
  118. int getstring(WINDOW *window, int y, int x, char *string, int n, 
  119.            int bg_color, int fg_color)
  120. {
  121.  int i;
  122.  char c='\0';
  123.  char tmp[n];
  124.  char tmp2[n];
  125.  
  126.  signal(SIGINT, handler);
  127.  strcpy(tmp2, string);
  128.  wattrset(window, fg_color);
  129.  for(i=0; i<n; i++)
  130.     {
  131.          mvwaddch(window, y, x+i, ACS_BOARD);
  132.      tmp[i]='\0';
  133.      string[i]='\0';
  134.     }
  135.  strcpy(string, tmp2);
  136.  mvwaddstr(window, y, x, string);
  137.  nodelay(stdscr, FALSE);
  138.  leaveok(stdscr, FALSE);
  139.  keypad(stdscr, FALSE);
  140.  refresh();
  141.  wrefresh(window);      //to have cursor
  142.  i=0;
  143.  while((c != '\n') && (c != ERR))
  144.  {
  145.       int j;
  146.  
  147.      c=wgetch(stdscr);
  148.     switch(c)
  149.     {
  150.      case ERR : break;
  151.      case '\n': break;
  152.      case '\033': if(wgetch(stdscr) == '[')
  153.             switch(wgetch(stdscr))
  154.             {
  155.              case 'D': // LEFT key
  156.                    if(tmp[0] == '\0') 
  157.                     {
  158.                      strcpy(tmp, string);
  159.                      i=strlen(string) + 1;
  160.                     }
  161.                    if(i > 0) 
  162.                     i--;
  163.                    break;
  164.              case 'C': //RIGHT key
  165.                    if((i < n-1) && (tmp[i] != '\0'))
  166.                         i++;
  167.                    break;
  168.              case 51: // DEL
  169.                   strncpy(&tmp[i], &tmp[i+1], n-i-1);
  170.                   tmp[n-1]='\0';
  171.  
  172.                   break;
  173.             }
  174.             nodelay(stdscr, TRUE);
  175.               while(wgetch(stdscr) != ERR);
  176.             nodelay(stdscr, FALSE);
  177.             break;
  178.          case 127: if(i >= 0) //BACKSPACE
  179.            {
  180.                if(i > 0) i--;
  181.             strncpy(&tmp[i], &tmp[i+1], n-i-1);
  182.             tmp[n-1]='\0';
  183.            }
  184.            break;
  185.      default: for(j=n-1; j>i; j--)
  186.             tmp[j]=tmp[j-1]; 
  187.           tmp[i]=c;
  188.           if(i < n-1) i++;
  189.           break;
  190. /* FOR TESTS!
  191.      default: mvwprintw(window, y, x, "                         ");
  192.           mvwprintw(window, y, x, "%3d ", c);
  193.           nodelay(window, TRUE);
  194.           while((c=wgetch(window)) != ERR)
  195.               wprintw(window, "%3d ", c);
  196.           nodelay(window, FALSE);  */
  197.     }
  198.     if(c != ERR) 
  199.     {
  200.           for(j=0; j<n; j++)
  201.             if(tmp[j] != '\0')
  202.                 mvwaddchar(window, y, x+j, tmp[j]);
  203.             else
  204.                 mvwaddch(window, y, x+j, ACS_BOARD);
  205.         wmove(window, y, x+i);
  206.         wrefresh(window);
  207.     }
  208.     
  209.  }
  210.  if(c != ERR)
  211.  {
  212.      if(tmp[0] != '\0')
  213.         strcpy(string, tmp);
  214.      wattrset(window, bg_color);
  215.      for(i=0; i<n; i++)
  216.         if(string[i] != '\0')
  217.             mvwaddchar(window, y, x+i, string[i]);
  218.         else
  219.             mvwaddch(window, y, x+i, ' ');
  220.     wmove(window, y, x+i);
  221.      wrefresh(window);
  222.  }
  223.  leaveok(stdscr, TRUE);    
  224.  refresh();
  225.  if(c == ERR)
  226.     return -1;
  227.  else
  228.     return 1;
  229. }
  230.  
  231. int WarningWindow (char *warning, char *yes, char *no)
  232. {
  233.  WINDOW *warnwin; 
  234.  int x, c, i;
  235.  int def_val = 1;   //possible values: 1 or -1
  236.  int result = 0;
  237.  
  238.  init_pair(59, COLOR_WHITE, COLOR_RED);
  239.  init_pair(60, COLOR_YELLOW, COLOR_RED);
  240.  
  241.  x = strlen(warning) + 4;
  242.  warnwin = newwin(7, x, LINES / 2 - 4, (COLS - x) / 2);
  243.  wattrset(warnwin, COLOR_PAIR(59) | A_BOLD);
  244.  for(i=0; i < 7 * x; i++)
  245.     waddch(warnwin, ' ');
  246.  box(warnwin, 0, 0);
  247.  
  248.  while(result == 0)
  249.  {
  250.     wattrset(warnwin, COLOR_PAIR(59) | A_BOLD);
  251.       mvwprintw(warnwin, 4, x/3 - 1, "  %s ", &yes[1]);
  252.       mvwprintw(warnwin, 4, 2*x/3 - strlen(no) - 1, "  %s ", &no[1]); 
  253.       mvwaddstr(warnwin, 2, 2, warning);
  254.       wattrset(warnwin, COLOR_PAIR(60) | A_BOLD);
  255.     if(def_val == 1)
  256.     {
  257.         mvwaddch(warnwin, 4, x/3 - 1, '[');
  258.         mvwaddch(warnwin, 4, x/3 + strlen(yes), ']');
  259.     }
  260.     else
  261.     {
  262.         mvwaddch(warnwin, 4, 2*x/3 - strlen(no) - 1, '[');
  263.         mvwaddch(warnwin, 4, 2*x/3, ']');
  264.     }
  265.       mvwaddch(warnwin, 4, x/3, yes[0]);
  266.       mvwaddch(warnwin, 4, 2*x/3 - strlen(no), no[0]);
  267.       wrefresh(warnwin);
  268.  
  269.     if( (c = tolower(wgetch(screen))) == tolower(yes[0]) )
  270.      {
  271.          delwin(warnwin);
  272.         result = 1;
  273.     }
  274.     else 
  275.         if(tolower(c) == tolower(no[0]))
  276.         {
  277.             delwin(warnwin);
  278.             result = -1;
  279.         }
  280.         else 
  281.             switch(c)
  282.             {
  283.              case 9: def_val = def_val * (-1); break;
  284.              case '\n': result = def_val; break;
  285.             }
  286.  }
  287.  if(result == 1)
  288.     return 1;
  289.  else
  290.     return 0; 
  291.  
  292. main(int argc, char *argv[])
  293. {
  294.  int     end = 0; 
  295.  int    c; 
  296.  
  297.  if(argc > 1)
  298.     interface = new Interface(0);
  299.  else
  300.     interface = new Interface(1);
  301.  
  302.  while(!end)
  303.  {
  304.      c=wgetch(screen);
  305.     switch(c)
  306.     {
  307.      case 'q': end=interface->back(); break;
  308.      case 'Q': end=interface->back(); break;
  309.      case '\033': end=interface->back(); break; //the escape key
  310.      case KEY_BACKSPACE: end=interface->back();
  311.      case '\n': interface->select(); break;
  312.      case '/': interface->search(); break;
  313.      case KEY_DOWN: interface->DOWN_ARROW(); break;
  314.      case KEY_UP: interface->UP_ARROW(); break;
  315.      case KEY_HOME: interface->HOME_KEY(); break;
  316.      case KEY_END: interface->END_KEY(); break;
  317.      case KEY_PPAGE: interface->PGUP_KEY(); break;
  318.      case KEY_NPAGE: interface->PGDN_KEY(); break;
  319.      case KEY_RIGHT: interface->RIGHT_ARROW(); break;
  320.      case KEY_LEFT: interface->LEFT_ARROW(); break;
  321.      case KEY_F(1): interface->help(); break;
  322.      case 'r': interface->enterletter('R'); break;
  323.      case 'R': interface->enterletter('R'); break;
  324.      case 'o': interface->enterletter('O'); break;
  325.          case 'O': interface->enterletter('O'); break;
  326.          case 'e': interface->enterletter('E'); break;
  327.          case 'E': interface->enterletter('E'); break;
  328.          case 'n': interface->enterletter('N'); break;
  329.          case 'N': interface->enterletter('N'); break;
  330.      case 's': interface->save(); break;
  331.      case 'S': interface->save(); break;
  332.      case 'k': interface->kill(); break;
  333.      case 'K': interface->kill(); break;
  334.      case 'a': interface->addressbook(); break;
  335.          case 'A': interface->addressbook(); break;
  336.      case KEY_F(2): interface->ReplyPacket(); break;
  337.      default: interface->ANY_KEY(); break;
  338.     }
  339.     if(!end) doupdate();
  340.  }
  341.  
  342.  delwin(screen);
  343.  touchwin(stdscr);
  344.  refresh();
  345.  leaveok(screen, FALSE);
  346.  echo();
  347.  system("clear");
  348. }
  349.